package com.v.partitionerAndwritable;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FlowDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //1获取job
        Configuration config = new Configuration();
        Job job = Job.getInstance(config);

        //2设置jar
        job.setJarByClass(FlowDriver.class);

        //3关联mapper和reducer
        job.setMapperClass(FlowMap.class);
        job.setReducerClass(FlowReducer.class);

        //4设置mapper 输出的key和value类型
        job.setMapOutputKeyClass(FlowBean.class);
        job.setMapOutputValueClass(Text.class);

        //5设置最终输出的key和value类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //设置partitioner分区的类别
        job.setPartitionerClass(partitionerandwritable.class);
        job.setNumReduceTasks(5);

        //设置路径
        FileInputFormat.setInputPaths(job, new Path("E:\\hadoop_Test\\InputFile\\self_sort_example"));
        FileOutputFormat.setOutputPath(job, new Path("E:\\hadoop_Test\\OutputFile\\partitionerAndwritable1"));

        //job的提交
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);


    }
}


























































